import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { JqtCpHtInfoVO, JqtCpHtInfoForm, JqtCpHtInfoQuery } from '@/api/bus/jqtCpHtInfo/types';
import { JqtCpInfoForm, JqtCpInfoQuery, JqtCpInfoVO } from '@/api/bus/jqtCpInfo/types';

/**
 * 查询企业互通信息列表
 * @param query
 * @returns {*}
 */

export const listJqtCpHtInfo = (query?: JqtCpHtInfoQuery): AxiosPromise<JqtCpHtInfoVO[]> => {
  return request({
    url: '/bus/jqtCpHtInfo/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询企业互通信息详细
 * @param id
 */
export const getJqtCpHtInfo = (id: string | number): AxiosPromise<JqtCpHtInfoVO> => {
  return request({
    url: '/bus/jqtCpHtInfo/' + id,
    method: 'get'
  });
};

/**
 * 新增企业互通信息
 * @param data
 */
export const addJqtCpHtInfo = (data: JqtCpHtInfoForm) => {
  return request({
    url: '/bus/jqtCpHtInfo',
    method: 'post',
    data: data
  });
};

/**
 * 修改企业互通信息
 * @param data
 */
export const updateJqtCpHtInfo = (data: JqtCpHtInfoForm) => {
  return request({
    url: '/bus/jqtCpHtInfo',
    method: 'put',
    data: data
  });
};

/**
 * 删除企业互通信息
 * @param id
 */
export const delJqtCpHtInfo = (id: string | number | Array<string | number>) => {
  return request({
    url: '/bus/jqtCpHtInfo/' + id,
    method: 'delete'
  });
};

/**
 * 修改企业信息
 * @param data
 */
export const editRemark = (data: JqtCpHtInfoForm) => {
  return request({
    url: '/bus/jqtCpHtInfo/editRemark',
    method: 'put',
    data: data
  });
};

/**
 * 获取企业互通授权链接
 * @param id
 */
export const getAuthUrl = (redirectUri:string): AxiosPromise<string> => {
  return request({
    url: '/bus/jqtCpHtInfo/getAuthUrl',
    method: 'post',
    data:{
      redirectUri:redirectUri
    }
  });
};

/**
 * 获取企业互通授权链接
 * @param id
 */
export const authCpCallback = (authCode:any,state:any,expiresIn:any): AxiosPromise<string> => {
  return request({
    url: '/bus/jqtCpHtInfo/authCpCallback',
    method: 'post',
    data:{
      authCode:authCode,
      state:state,
      expiresIn:expiresIn
    }
  });
};

/**
 * 查询企业互通信息列表
 * @param query
 * @returns {*}
 */

export const getCpList = (query?: JqtCpHtInfoQuery): AxiosPromise<JqtCpHtInfoVO[]> => {
  return request({
    url: '/bus/jqtCpHtInfo/getList',
    method: 'get',
    params: query
  });
};

/**
 * 获取企业互通授权链接
 * @param id
 */
export const getAgentConfig = (url:string,corpId:string): AxiosPromise<string> => {
  return request({
    url: '/api/getAgentConfig',
    method: 'post',
    data:{
      url:url,
      corpId:corpId
    }
  });
};


/**
 * 查询我的企微互通企业信息列表
 * @param query
 * @returns {*}
 */

export const getMyCpHtInfo = (query?: JqtCpHtInfoQuery): AxiosPromise<JqtCpHtInfoVO[]> => {
  return request({
    url: '/bus/jqtCpHtInfo/getMyCpHtInfo',
    method: 'get',
    params: query
  });
};
